#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T,n,a[MAX];
    int dp[MAX][2];
    cin>>T;
    while(T--)
    {
        cin>>n;
        for(int i = 1;i <= n;i++)
        {
            cin>>a[i];
        }
        if(n <= 20)
        {
            long long maxan = -1;
            for(int j = 0;j <= (1<<n)-1;j++)
            {
                long long ans = 0;
                for(int k = 0;k <= n;k ++)
                {
                    for(int l = k-1;l >=0;l--)
                    {
                       // cout<<(int)(j&&(1<<k))<<" "<<(j&&(1<<l))<<endl;
                        if(j&&(1<<k) == j&&(1<<l))
                        {
                            //cout<<"t"<<endl;
                            if(a[k] == a[l])ans+=a[k];
                            break;
                        }

                    }

                }
                maxan = max(ans,maxan);
            }
            cout<<maxan<<endl;
        }
        int lst0;

    }
    return 0;
}
